#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

bool isPrime(int num) {
    if (num <= 1) 
        return false;
    for (int i = 2; i * i <= num; i++) {
        if (num % i == 0) 
            return false;
    }
    return true;
}

int wordToNum(const string& word1, const string& word2, const string& word3) {
    vector<string> wordDict = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    int num1 = find(wordDict.begin(), wordDict.end(), word1) - wordDict.begin();
    int num2 = find(wordDict.begin(), wordDict.end(), word2) - wordDict.begin();
    int num3 = find(wordDict.begin(), wordDict.end(), word3) - wordDict.begin();

    return num1 * 100 + num2 * 10 + num3;
}

int main() {
    string input, word1, word2, word3;
    getline(cin, input);
    istringstream iss(input);
    int temp;
    if (!(iss >> word1 >> word2 >> word3) || (iss >> temp)) {
        cout << "Wrong input" << endl;
        return 1;
    }

    int num = wordToNum(word1, word2, word3);

    if (num < 100 || num > 999) { 
        cout << "Wrong input" << endl; 
        return 1;
    }

    int lower = num, higher = num;
    while (true) {
        if (isPrime(lower)) {
            cout << lower << endl;
            return 0;
        }
        if (isPrime(higher)) {
            cout << higher << endl;
            return 0;
        }
        lower--;
        higher++;
    }

    return 0;
}

